<?php

require_once '../include/common.php';
ignore_user_abort();
set_time_limit(0); 
$file = "cache/pl.db";
$hs_num = file_get_contents($file);
$hs= $hs_num + 1;
file_put_contents($file, $hs);

function w_pl($qq,$sid,$con){
	$url="http://ish.z.qq.com/feeds_friends.jsp?B_UID={$qq}&sid={$sid}_-e&type=all&g_ut=1";
	$result=cget($url);
	preg_match_all('@<a href="http://info(.*).z.qq.com/infocenter/myfeed_mood.jsp\?sid=(.*)B_(.*)_source(.*)">评论\(0\)</a>@',$result,$url_array);
	$n=count($url_array['3']);
	for($i=0;$i<$n;$i++){

		$ur=html_entity_decode($url_array[3][$i]) ;
		$content=($con!="")?w_ubb($con).$ad:w_ubb("[随机]").$ad; 
		$surl="http://blog30.z.qq.com/mood/mood_reply.jsp?sid={$sid}&g_ut=1";

		$post="B_{$ur}_source=1&comeFrom=mainpage_guest&content=".urlencode($content);
		$ch=curl_init(); 
		curl_setopt($ch,CURLOPT_URL,$surl);
		curl_setopt($ch,CURLOPT_TIMEOUT,100);
		curl_setopt($ch,CURLOPT_USERAGENT,'TTMobile/09.03.18/symbianOS9.1 Series60/3.0 Nokia6120cAP3.03');
		curl_setopt($ch,CURLOPT_NOBODY,1);
		curl_setopt($ch,CURLOPT_RETURNTRANSFER,1);
		curl_setopt($ch,CURLOPT_POST,1);
		curl_setopt($ch,CURLOPT_POSTFIELDS,$post);
		$r=curl_exec($ch);
		curl_close($ch);

	}
}

	$z_sql = "SELECT `gqid` FROM `w_qq` WHERE pl='1' AND zt='1'";
	$z_sth = $db->query($z_sql);
	$z_num = $z_sth->rowCount();
	
	$num=ceil($z_num / $run_num);
	

	$now_num=($hs_num%$num)*$run_num;
	
	$pl_sql = "SELECT `qq`,`sid`,`pldata` FROM `w_qq` WHERE pl='1' AND zt='1' limit {$now_num},{$run_num}";
	$pl_sth = $db->query($pl_sql);
	$pl=$pl_sth->fetchAll();
	
	foreach ($pl as $value) {
		w_pl($value[qq],$value[sid],$value[pldata]);
		
	}
	
echo 'ok';
?>